﻿#ifndef FILEOPERATION_H
#define FILEOPERATION_H

#include <QFile>
#include <QXmlStreamReader>
#include <QDebug>
#include<QFileDialog>
#include<QMessageBox>
#include <QTextStream>
#include <QWidget>
#include <QDir>
#include <QCoreApplication>
#include <QDateTime>
#include <QFile>
#include <QApplication>
#include <QRegularExpression>
#include <QDomDocument>
#include <QDomElement>
#include <QDomNodeList>
extern std::list<QString> SourceFilePath;//路径容器
class FileOperation
{
public:
    int  UploadRate;//最大上传速率
      int  UploadNum;//上传机器数量速率
      bool pauseFlag=false;
      bool UploadpauseFlag=false;
      bool DiskReachMax=false;
      QString IndexDrive;  //索引盘符
      QString Name;//采集站名称
      QString Version;//版本号
      QString Model;//采集站类型
      QString Datetime;//版本时间
      QString Icon;//图标
      QString BVersion;//后台版本号
      QString URL;//后台地址
      QString Ttime;//后台心跳时间
      QString Btime;//公告心跳时间
      QString MoltiDisk;//多盘路径
      QString Mapping;//接口映射
      QString ServerAddress;//服务端IP
      QString ServerPor;//服务端端口
      QString Sockettime;//Socket重接时间
      QString UploadUrl ;//上传路径
      QString MountUrl ;//挂载根目录
      QString VideoEncryption;//视频加密
      QString DeleteFiles;//删除视频
      QString WhiteList;//白名单
      QString MUI;//语言包
      QString MemoryLack;//内存不足报警
      QString CPULack;//CPU不足报警
      QString TheLocalKey;//账号
      QString TheLocalKeyPDW;//密码
      QString Area;//地区
      QString Mode;//上传模式
      QString MaxUploadRate;//最大上传速率
      QString prior;//优先口
      QString System;//系统
      QString List;
      QString Row;
 QString PortNum;
QString NetwordName;
    struct FileInfo
    {
        QString fileName;//文件名字
        QString lastModified;// 修改时间
        QString sourceFilePath;//路径
        QString officerID;//警员编号
        QString productNumber;//序列号
    };
    std::list<FileInfo> filelist;//文件链表
    std::list<QString>  video;
    std::list<QString>  log;
    std::list<QString>  picture;
    std::list<QString>  audio;
bool IsUpload[26];//是否上传 true为继续上次，false反之
bool PrintLog=true;//是否打印日记
int IsPriority=-1;
public:
    FileOperation();
    bool ReadLicenseInfo(QString ConfigName,QString key,QString &value);
    bool ReadInfo(QString ConfigName);
    bool ReadRouteInfo(QString ConfigName,QString key,QString &value);
    bool ReadRouteValueInfo(QString ConfigName,QString &key,QString value);
    bool WriteInfo(QString key);
    bool WriteInfo(QString key,QString value);
    //根据key值修改路径文件
    bool UpdateRouteValueInfo(QString ConfigName,QString key,QString value);

    bool WriteSaveInfo(QString ConfigName,QString key,QString value);
   // bool WriteSaveInfo(QString serialize,QString filename,QString time,QString filetime,QString Username);
    //清空保存文件
    bool DeleteSaveInfo(QString ConfigName);
    void findLogFiles(const QString& path);
    void findFilesByCreationDate(const QString& path, const QString& startDate, const QString& endDate, const QString& OfficerID, const QString& productNumber);
    void findFilesByCreationDate(const QString& path);

    void GetTotalSizeOfFiles(const QString &directoryPath, double &totalSize);
    bool WriteZFYConfig(QString Disk, QString DeviceID, QString MName, QString Model);

    void findFileLog(const QString &path);
    bool WriteSaveInfo(QString serialize, QString filename, QString time, QString filetime, QString Username, const QString &destinationDirPath);
    bool WriteSaveInfo(QString serialize, QString filename, QString time, QString filetime, QString Username, QString case_number, QString trafficCaseTable, QString file_type_id, const QString &destinationDirPath);
    qint64 getFolderSize(const QString &folderPath);
    int copyFiles(const QString &sourceDirPath, const QString &destinationDirPath, const QString &serialnumber, const QString &timestr, const QString &Badgenum, const QString Device, bool DeleteFiles, QString case_number, QString trafficCaseTable, QString file_type_id, int &num, int MaxSpeed);
    int copyFiles(const QString &sourceDirPath, const QString &destinationDirPath, const QString &serialnumber, const QString &timestr, const QString &Badgenum, const QString Device, bool DeleteFiles, int &num, int MaxSpeed, int serialportnum);
    QString validateFileName(QString fileName);
    bool WriteSaveInfo(QString serialize, QString filename, QString time, QString filetime, QString Username, QString case_number, const QString &destinationDirPath);

    bool ReadVerInfo(QString ConfigName, QString key, QString &value);
    QString extractTimestamp(const QString &filename);
    bool UpdateXmlKeyValue(const QString &filePath, const QString &key, const QString &newValue);
    bool ReadInfo(QString ConfigName, QString &value);
};


#endif // FILEOPERATION_H
